<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\Carousel;
use app\common\model\News;
use app\common\model\ProductCate;
use think\facade\Cache;
use think\facade\View;

class Index extends Base
{

    public function index()
    {

        $carousel = Carousel::getList(['type' => 1], true, 'sort', [], 'id,images,link');
        $cate = ProductCate::where(['status' => 1, 'is_del' => 0, 'pid' => 0])->field('id,title,icon')->select();
        $news = News::getList(['type' => 2], true, 'sort', [], 'id,title');
        $result = [
            'carousel' => $carousel,
            'news' => $news,
            'cate' => $cate
        ];
        return json(['code' => 1, 'msg' => 'success', 'result' => $result]);

    }

    public function communal()
    {
        $type = $this->request->param('type');
        $title = ['company' => '公司介绍', 'register_msg' => '注册协议'];

        View::assign([
            'title' => $title[$type],
            'content' => Cache::get('system')[$type]
        ]);
        return View::fetch();
    }
}
